Challenge 7: Incorporating Multiple Inputs

Functions + Fish

Author

Your name

Download .qmd starter file

Download BlackfootFish.csv

This is a continuation of Lab 7: Functions + Fish.

library(tidyverse)
fish <- read.csv("../lab_assignments/lab7/BlackfootFish.csv")

A frequently used measurement for fish health is a condition index (Wikipedia article). The following simple equation can be used to calculate the approximate condition index of a fish:

\[\text{condition index} = \frac{weight}{length^3} \times 100\]

1. There are specific units required for the calculation of a condition index – length must be in millimeters and weight must be in grams. Inspect the length and weight variables to decide if you believe these are the correct units associated with the measurements in our dataset. If they are not, convert the measurements.

Tip

This will likely require Googling what “typical” measurements of trout are.

# Question 1 code

2. Replace impossible measurements with NAs, using your research to determine what measurements are unlikely or impossible. Write a function(s) to handle this process.

Your function(s) should accept three inputs

If a value falls outside these bounds, you should replace it with an NA.

Tip

If you are struggling with the structure of your function, I would suggest reading the Mutating Function from R4DS.

Use your function to modify the length and weight columns of the BlackfootFish data set, removing values you believe are unreasonable.

# Question 2 code

3. Write a function to calculate the condition index of a fish, given inputs of weight and length.

Warning

Consider whether your function will accept vectors as inputs or if it will accept variable names as inputs!

# Question 3 code

4. Make a thoughtful visualization of how fish conditions have varied over the duration of this study.

# Question 4 code